// pages/info/tea/tea.js
const app = getApp();
Page({
  data: {
    name: '',
    number: '',
    phone: '',
    userid: '',
    who: "学生",
    tips: "信息一经注册无法修改，请认真填写哟😘",

    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl')
  },



  gohome: function (e) {
    var that = this;
    if ((that.data.name && that.data.number && that.data.phone) != '') {
      // console.log(that.data)
      this.charu()
    } else {
      wx.showToast({
        title: '您有信息未输入哦',
        icon: 'none'
      })
    }
  },
  //获取input的信息
  setname: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  setnumber: function (e) {
    this.setData({
      number: e.detail.value
    })
  },
  setphone: function (e) {
    this.setData({
      phone: e.detail.value,
    })
  },


  charu: function () {
    var that = this;
    var userid = wx.getStorageSync('openid');
    // console.log(userid)
    wx.request({
      url: app.globalData.ServerUrl + 'stuLogin.php',
      data: {
        userid: userid,
        name: that.data.name,
        number: that.data.number,
        phone: that.data.phone,
        who: that.data.who
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data)
        if (res.data == "student_login_success") {
          wx.showToast({
            title: '注册成功！',
            icon: 'success'
          })
          setTimeout(() => {
            wx.reLaunch({
              url: '../../home/home/home?who=0'
            })
          }, 1000);

        } else {
          wx.showToast({
            title: '失败请重试！😱',
            icon: 'none'
          })
        }
      },
      fail: function (res) {},
      complete: function (res) {},
    })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }

})